import Vue from 'vue'
import Vuex from 'vuex'
import getters from "./getters.js"
// import * as actions from './actions'
// import * as getters from './getters'
// import cart from './modules/cart'
// import products from './modules/products'
// import createLogger from '../../../src/plugins/logger'

Vue.use(Vuex)

const debug = process.env.NODE_ENV !== 'production'

export default new Vuex.Store({
    state: {
        title: '',
        gender: {'1': '男', '2': '女'},
        political_outlook: {'1': '群众', '2': '党员'},
        selection:{},
        fieldLists: {},
        weChat_type:{},
        weChat_name:{},
        user:{},
        years:{},
        replyTypeList : {'1':'文本','2':'图片','3':'图文','4':'音频','5':'视频'},
        on_line_weChat_name:'未选择',
        on_line_weChat_id:0,
        organizational:{},
        org_list:{},
        roles:[],
        permissions:{},
        role:{}
    },
    mutations: {
        setTitle (state, title) {
            // 变更状态
            state.title = title;
        },
        setUserinfos (state,infos){
            state.user = infos;
        },
        setUserRoles(state,roles){
          state.roles = roles;
        },
        setYears (state,infos){
            state.years = infos;
        },
        setWeChatTypes (state,infos){
            state.weChat_type = infos;
        },
        setWeChatNames (state,infos){
            state.weChat_name = infos;
        },
        seton_line_weChat_name(state,name){
            sessionStorage.setItem('weChat_name', name);
            state.on_line_weChat_name =name;
        },
        seton_line_weChat_id(state,id){
            sessionStorage.setItem('weChat_id', id);
            state.on_line_weChat_id = id;
        },
        set_field(state,infos){
            state.fieldLists=infos
        },
        set_selection(state,infos){
            state.selection=infos
        },
        set_organizational(state,infos){
            state.organizational = infos
        },
        set_org_list(state,infos){
            state.org_list = infos
        },
        setPermissions(state,infos){
            state.permissions = infos
        },
        setRoles(state,infos){
            state.role = infos
        }
        // setProperties(state, properties){
        //     state.properties = properties;
        // }
    },
    actions: {
        // fetchProperty({commit}){
        //     axios.get('api/users').then(function (response) {
        //         let properties = {};
        //         _.each(response.data, function (value) {
        //             if (typeof properties[value.type] == 'object') {
        //                 properties[value.type][value.key] = value.value;
        //             } else {
        //                 properties[value.type] = {};
        //                 properties[value.type][value.key] = value.value;
        //             }
        //         })
        //         commit('setProperties', properties);
        //     }).catch(function (error) {
        //         // Something happened in setting up the request that triggered an Error
        //     });
        // },
        getUserinfo({commit}){
            axios.get('api/user-infos/'+window.Laravel.apiToken).then(function (response) {
                commit('setUserinfos', response.data);
            }).catch(function (error) {
                // Something happened in setting up the request that triggered an Error
            });
            axios.get('api/user-roles/'+window.Laravel.apiToken).then(function (response) {
                commit('setUserRoles', response.data);
            }).catch(function (error) {
                // Something happened in setting up the request that triggered an Error
            });
            axios.get('api/see-semesters').then(function (response) {
                commit('setYears', response.data);
            }).catch(function (error) {
                // Something happened in setting up the request that triggered an Error
            });
            axios.get('api/permissions').then(function (response) {
                commit('setPermissions', response.data);
            }).catch(function (error) {
                // Something happened in setting up the request that triggered an Error
            });
            axios.get('api/roles-list').then(function (response) {
                commit('setRoles', response.data);
            }).catch(function (error) {
                // Something happened in setting up the request that triggered an Error
            });
            axios.get('api/WeChat/type').then(function (response) {
                commit('setWeChatTypes', response.data);
            }).catch(function (error) {
                // Something happened in setting up the request that triggered an Error
            });
            // axios.get('api/WeChat/name-list').then(function (response) {
            //     commit('setWeChatNames',response.data );
            // }).catch(function (error) {
            //     // Something happened in setting up the request that triggered an Error
            // });
            // axios.get('api/classGroup/field').then(function (response) {
            //     commit('set_field',response.data );
            // }).catch(function (error) {
            //     // Something happened in setting up the request that triggered an Error
            // });
            axios.get('api/classGroup/selection').then(function (response) {
                commit('set_selection',response.data );
            }).catch(function (error) {
                // Something happened in setting up the request that triggered an Error
            });

            // axios.get('api/companys-list').then(function (response) {
            //     commit('setCompanys', response.data);
            // }).catch(function (error) {
            //     // Something happened in setting up the request that triggered an Error
            // });
            // axios.get('api/posts-list').then(function (response) {
            //     commit('setPosts', response.data);
            // }).catch(function (error) {
            //     // Something happened in setting up the request that triggered an Error
            // });
        },
        getDefaultWeChat({commit}){
            axios.get('api/WeChat/get-default').then(function (response) {
                commit('seton_line_weChat_name',response.data.name );
                commit('seton_line_weChat_id',response.data.id );
            }).catch(function (error) {
                // Something happened in setting up the request that triggered an Error
            });
        },
        getOrg({commit}){
            axios.get('api/organizational').then(function (response) {
                commit('set_organizational',response.data);
            }).catch(function (error) {
                // Something happened in setting up the request that triggered an Error
            });
            axios.get('api/org-list').then(function (response) {
                commit('set_org_list',response.data);
            }).catch(function (error) {
                // Something happened in setting up the request that triggered an Error
            });
        }
    },
    getters,
    strict: debug,
    // plugins: debug ? [createLogger()] : []
})
